package com.tl.juc.c1;

public class InterruptThread {
    public static void main(String[] args) {
        Thread thread = new Thread( () ->
        {
            while (true) {
                // 每隔1s睡眠一下，清除时间片
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                     // 当出现InterruptedException异常的时候，会把中断标记修改为false
                    e.printStackTrace();
                    // 再次加上中断标记
                    Thread.currentThread().interrupt();
                }
                // 获取当前中断标记,将中断标记改为false
                System.out.println(Thread.currentThread().isInterrupted());
                // 单纯获取当前中断标记
                if (Thread.interrupted()) {
                    System.out.println(Thread.currentThread().isInterrupted());
                    // 如果中断标记是true，就break
                    break;
                }
                // 定时监控系统
                System.out.println("定时监控...");
            }
        } );
        thread.start();
        // 只是通知线程需要中断，中断标记为true
        thread.interrupt();

    }
}
